<template>
  <nav-bar>
    <template v-slot:default>确认订单</template>
  </nav-bar>
  <div class="detailList">
    <div class="title">
      <p style="color:rgb(169, 164, 164);font-size:18px">存入金额（元）</p>
      <p style="font-size:42px"><small>￥</small>{{ list[flag1].money }}</p>
    </div>
    <div class="detail">
      <div class="line1 line">
        <p style="margin-right:auto">产品名称</p>
        <p>{{ list[flag1].year }}年定期存款</p>
      </div>
      <div class="line2 line">
        <p style="margin-right:auto">币种</p>
        <p>人民币</p>
      </div>
      <div class="line3 line">
        <p style="margin-right:auto">存期</p>
        <p>{{ list[flag1].year }}年</p>
      </div>
      <div class="line4 line">
        <p style="margin-right:auto">年利率</p>
        <p>{{ list[flag1].rate }}%</p>
      </div>
      <div class="line5 line">
        <p style="margin-right:auto">转入账户</p>
        <p>212364348</p>
      </div>
    </div>
  </div>
  <el-button type="success" class="btn" @click="toFinal">确定</el-button>
</template>

<script>
import { useRouter } from "vue-router";
import { useRoute } from "vue-router";
import { reactive, toRefs } from "vue";
import NavBar from "../../components/common/navbar/NavBar.vue";
import { buyRealProduct } from "@/api/product";
export default {
  components: {
    NavBar,
  },

  setup() {
    const router = useRouter();
    const route = useRoute();
    const state = reactive({
      cardNumber: 0,
      id: 0,
      list: [],
      flag1: 0,
      chusValue: 0,
    });
    state.id = route.query.id;
    state.cardNumber = localStorage.getItem("payAccount");
    state.chusValue = localStorage.getItem("chuvalue");
    state.list = JSON.parse(localStorage.getItem("availableList"));
    const toFinal = async () => {
      await buyRealProduct(state.id, state.cardNumber, state.chusValue);
      router.push("/final");
    };
    const initPay = async () => {
      for (let it = 0; it < state.list.length; it++) {
        if (state.list[it].id == state.id) {
          state.flag1 = it;
        }
      }
    };
    initPay();
    return {
      ...toRefs(state),
      toFinal,
    };
  },
};
</script>
<style lang="scss" scoped>
.detailList {
  padding: 0 5%;
  padding-bottom: 5%;
  width: 90%;
  margin: 60px auto;
  border: 1px solid #efefef;
  background-color: #fff;
  border-radius: 15px;
  box-shadow: 0 0 8px #fff, 0 5px 13px rgb(0 0 0 / 7%);
}
.title {
  padding-bottom: 10px;
  border-bottom: 2px solid #efefef;
  text-align: center;
  line-height: 48px;
}
.line {
  display: flex;
  line-height: 50px;
  font-size: 18px;
}
.btn {
  width: 60%;
}
</style>
